package org.voidness.oje2d.gui;

import org.voidness.oje2d.GLColor;
import org.voidness.oje2d.GLFont;

/** A label widget to use with the GUI engine */
public class Label extends Widget {
    /** The text */
    private String text = null;

    /** The color of the label text */
    private GLColor color = null;

    /** The font to use when drawing */
    private GLFont font = null;

    /** The zoom factor of the text */
    private float zoom;

    /**
     * Default constructor
     * 
     * @param mText The text of the label
     * @param mColor The color of the text
     * @param mFont The font to use
     * @param mZoom The zoom factor for the text
     */
    public Label(String mText, GLColor mColor, GLFont mFont, float mZoom) {
        // Call the widget's constructor
        super(mText.length() * mFont.getCharSize(), mFont.getCharSize());

        text = mText;
        color = mColor;
        font = mFont;
        zoom = mZoom;

        // Set this widget in 0,0 relative to it's parent
        xPos = 0;
        yPos = 0;
    }

    /**
     * Another constructor. This defines the position for the label inside the
     * parent
     * 
     * @param mX The X component of the label location
     * @param mY The Y component of the label location
     * @param mText The text for the label
     * @param mColor The text color
     * @param mFont The font to use when drawing
     * @param mZoom The text's zoom factor
     */
    public Label(int mX, int mY, String mText, GLColor mColor, GLFont mFont,
            float mZoom) {
        super(mX, mY, mText.length() * mFont.getCharSize(), mFont.getCharSize());

        text = mText;
        color = mColor;
        font = mFont;
        zoom = mZoom;
    }

    /**
     * (Re)defines the label's text
     * 
     * @param mText The text to set
     */
    public void setText(String mText) {
        text = mText;
    }

    /**
     * Draws the widget and all sub-widgets.
     */
    public void draw(GLColor mColor) {
        // Draw only if visible
        if (!visible)
            return;

        // font.setZoom(zoom);
        font.print(text, xPos + parent.getXPos(), yPos + parent.getYPos(),
                zoom, color);

        // Cycle the widget list and draw all
    }
}